import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { writeFile } from "fs";
import { saveImage, saveVideo, sendToServer } from "./tooler"

@Injectable()
export class AppService {
    getHello(): string {
        return 'Hello World!';
    }

    async downloadImage(src: string) {
        const n = await saveImage(src);
        return n;
    }

    async downloadVideo(param: any) {
        // video: link,   ...mp4
        // src: url,   /weer554
        // size: arr[0].size   480x1280
        const { video, src, size } = param;
        const n = await saveVideo(video, src, size);
        return n;
    }

    async uploadVideo(param: any) {
        const { name } = param;
        // video: link,   ...mp4
        // src: url,   /weer554
        // size: arr[0].size   480x1280

        const localfile = "/root/vol/" + name;
        const remoterfile = "/root/www/proxy/videos/" + name;
        sendToServer(localfile, remoterfile);
        return name;
    }
}
